var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}), (o.ShareMessageToFriendScene = void 0);
var n,
    r = t("Files"),
    a = t("ConfS"),
    i = t("Const"),
    s = t("LingquJiangli"),
    c = t("Platforms"),
    l = t("Scores");
(function (t) {
    (t[(t["纯分享"] = 1)] = "纯分享"),
        (t[(t["邀请对战"] = 2)] = "邀请对战"),
        (t[(t["送钻石"] = 3)] = "送钻石"),
        (t[(t["领奖励"] = 4)] = "领奖励");
})((n = o.ShareMessageToFriendScene || (o.ShareMessageToFriendScene = {})));
var u = (function () {
    function t() {}
    return (
        (t.init = function (t) {
            for (var e = this, o = [], r = 1; r < arguments.length; r++) o[r - 1] = arguments[r];
            "undefined" != typeof sharedCanvas &&
                ((sharedCanvas.width = 2048),
                (sharedCanvas.height = 2048),
                (this.used = !0),
                this.postMessage("init", {uiInfoss: [t, c.default.atlas.getUIInfos("platforms")], actions: o}),
                wx.onShareMessageToFriend &&
                    wx.onShareMessageToFriend(function (t) {
                        t.success &&
                            (c.default.userStorage.加玩家总次数("shareSuccess"),
                            l.scores.add("定向分享加分", a.DatasManager.每分享一次得分)),
                            c.default.platformCtrl.toast(t.success ? "分享成功！" : "分享失败！"),
                            e.postMessage("onShareMessageToFriend", {success: t.success}),
                            e.onRefreshPotentialFriend &&
                                (e.onRefreshPotentialFriend(t.success),
                                (e.onRefreshPotentialFriend = null),
                                (e.currPotentialFriendIcon = null));
                    }),
                wx.onInteractiveStorageModified &&
                    wx.onInteractiveStorageModified(function (t) {
                        switch (parseInt(t)) {
                            case n.送钻石:
                                c.default.popups
                                    .show(s.LingquJiangli)
                                    .set(
                                        a.DatasManager.好友助力奖励货币,
                                        a.DatasManager.每邀请一位好友送出奖励数,
                                        1,
                                        "刚刚，就刚刚！有个好基友给你送温暖！"
                                    );
                                break;
                            case n.领奖励:
                                e.onRefreshPotentialFriend &&
                                    (i.default.addMoney(
                                        a.DatasManager.好友助力奖励货币,
                                        a.DatasManager.每成功邀请一位好友获得奖励数,
                                        "成功邀请一位好友获得奖励",
                                        e.currPotentialFriendIcon,
                                        null
                                    ),
                                    e.onRefreshPotentialFriend(!0),
                                    (e.onRefreshPotentialFriend = null),
                                    (e.currPotentialFriendIcon = null));
                        }
                    }),
                (this.getFriendCloudStorageTime = 0));
        }),
        (t.setOpenId = function () {
            this.used && this.postMessage("setOpenId", {selfOpenId: c.default.userStorage.openId});
        }),
        (t.firstSaveUserCloudStorage = function () {
            this.isFirstSaveUserCloudStorage || ((this.isFirstSaveUserCloudStorage = !0), this.saveUserCloudStorage());
        }),
        (t.saveUserCloudStorage = function () {
            if (this.used) {
                var t = c.default.userStorage.getUserCloudStorage();
                t && this.postMessage("saveUserCloudStorage", {data: t});
            }
        }),
        (t.get = function (t, e) {
            if (this.used) {
                var o = new cc.Node();
                (o.anchorX = 0), (o.anchorY = 1);
                for (
                    var n = new cc.Texture2D(), r = Math.floor(2048 / t), a = e * Math.floor(2048 / e), i = 0;
                    i < r;
                    i++
                ) {
                    var s = new cc.Node();
                    o.addChild(s), (s.anchorX = 0), (s.anchorY = 1), (s.x = 0), (s.y = -a * i);
                    var c = s.addComponent(cc.Sprite),
                        l = new cc.SpriteFrame(n, new cc.Rect(i * t, 0, t - 2, a));
                    c.spriteFrame = l;
                }
                return (o.width = t), (o.height = a * r), (o.tex = n), (o.cap = t), (o.gap = e), o;
            }
        }),
        (t.draw = function (t) {
            for (var e = [], o = 1; o < arguments.length; o++) e[o - 1] = arguments[o];
            this.used && (this.postMessage("draw", {cmds: e}), this.refresh(t));
        }),
        (t.refresh = function (t) {
            if (this.used)
                switch (c.default.platformType) {
                    case "QQ小程序":
                    case "红包QQ":
                        c.default.delays.delay({
                            time: 0.1,
                            action: function () {
                                t.tex.initWithElement(sharedCanvas);
                            }
                        });
                        break;
                    default:
                        t.tex.initWithElement(sharedCanvas);
                }
        }),
        (t.如有必要把远程图片下载到本地 = function (t, e) {
            switch (c.default.platformType) {
                case "QQ小程序":
                case "红包QQ":
                    var o = t.replace(/^.+\/([^\/]+)$/, "$1"),
                        n = r.Files.cdnPath + o;
                    this.fs || (this.fs = wx.getFileSystemManager()),
                        this.fs.access({
                            path: n,
                            success: function () {
                                e(n);
                            },
                            fail: function () {
                                wx.downloadFile({
                                    url: t,
                                    filePath: n,
                                    success: function (t) {
                                        e(n);
                                    },
                                    fail: function (e) {
                                        console.error("下载失败 " + t + "\n" + n + "\n" + JSON.stringify(e));
                                    }
                                });
                            }
                        });
                    break;
                default:
                    e(t);
            }
        }),
        (t.shareMessageToFriend = function (t) {
            var e = this;
            if (this.used) {
                (this.onRefreshPotentialFriend = null),
                    (this.currPotentialFriendIcon = null),
                    wx.setMessageToFriendQuery && wx.setMessageToFriendQuery({shareMessageToFriendScene: n.纯分享});
                var o = c.default.platformCtrl.getShare();
                (o.userDataIndex = t),
                    this.如有必要把远程图片下载到本地(o.imageUrl, function (t) {
                        (o.imageUrl = t), e.postMessage("shareMessageToFriend", o);
                    });
            }
        }),
        (t.clickPotentialFriend = function (t, e, o) {
            var r = this;
            if (this.used) {
                (this.onRefreshPotentialFriend = o),
                    (this.currPotentialFriendIcon = e),
                    wx.setMessageToFriendQuery && wx.setMessageToFriendQuery({shareMessageToFriendScene: n.送钻石});
                var i = c.default.platformCtrl.getShare(a.DatasManager.邀请好友分享);
                (i.title = i.title.replace("${num}", a.DatasManager.每邀请一位好友送出奖励数.toString())),
                    (i.userDataIndex = t),
                    this.如有必要把远程图片下载到本地(i.imageUrl, function (t) {
                        (i.imageUrl = t), r.postMessage("clickPotentialFriend", i);
                    });
            }
        }),
        (t.clickFakeFriend = function () {
            var t = this;
            if (this.used) {
                wx.setMessageToFriendQuery && wx.setMessageToFriendQuery({shareMessageToFriendScene: n.送钻石});
                var e = c.default.platformCtrl.getShare(a.DatasManager.邀请好友分享);
                (e.title = e.title.replace("${num}", a.DatasManager.每邀请一位好友送出奖励数.toString())),
                    this.如有必要把远程图片下载到本地(e.imageUrl, function (o) {
                        (e.imageUrl = o), t.postMessage("clickFakeFriend", e);
                    });
            }
        }),
        (t.modifyFriendInteractiveStorage = function (t) {
            this.postMessage("modifyFriendInteractiveStorage", {key: "" + t});
        }),
        (t.getFriendCloudStorage = function () {
            var t = new Date().getTime();
            t - this.getFriendCloudStorageTime > 6e4 &&
                ((this.getFriendCloudStorageTime = t), this.postMessage("getFriendCloudStorage"));
        }),
        (t.inviteFriend = function (t, e) {
            var o = this;
            this.used &&
                ((this.onRefreshPotentialFriend = null),
                (this.currPotentialFriendIcon = null),
                wx.setMessageToFriendQuery && wx.setMessageToFriendQuery({shareMessageToFriendScene: n.邀请对战}),
                ((e = c.default.platformCtrl.getShare(e)).userDataIndex = t),
                this.如有必要把远程图片下载到本地(e.imageUrl, function (t) {
                    (e.imageUrl = t), o.postMessage("inviteFriend", e);
                }));
        }),
        (t.inviteFriendByOpenId = function (t) {
            this.used && this.postMessage("inviteFriendByOpenId", {openId: t});
        }),
        (t.postMessage = function (t, e) {
            void 0 === e && (e = {}), wx.getOpenDataContext && ((e.action = t), wx.getOpenDataContext().postMessage(e));
        }),
        t
    );
})();
o.default = u;
